var page = sm("do_Page");
var nf = sm("do_Notification");
var openHelper = require("helper/open");
var friendHelper = require("helper/friend");
var rootView = ui("$");
rootView.setMapping({
	"lableTime.tag":"id",
	"imgfullLogo.tag":"userId",
	"imgfullLogo.source":"fullUserLogo",
	"lableName.text":"userName",
	"lableActionDesc.tag" : "status",
	"lableActionDesc.text" : "",
	"lableTime.text" : "cnNewAt"
});

rootView.on("dataRefreshed", function(){
	//status: 1-待处理;2-已接受;3-已忽略;4-已拒绝'
	var status = ui("lableActionDesc").tag;//状态
	if(status=="1"){
		ui("btnAccept").visible = true;
		ui("btnIgnore").visible = true;
		ui("lableActionDesc").visible = false;
	}else if(status=="2"){
		ui("lableActionDesc").text = "已添加";
		ui("lableActionDesc").visible = true;
		ui("btnAccept").visible = false;
		ui("btnIgnore").visible = false;
	}else if(status=="3"){
		ui("lableActionDesc").text = "已忽略";
		ui("lableActionDesc").visible = true;
		ui("btnAccept").visible = false;
		ui("btnIgnore").visible = false;
	}else if(status=="4"){
		ui("lableActionDesc").text = "已拒绝";
		ui("lableActionDesc").visible = true;
		ui("btnAccept").visible = false;
		ui("btnIgnore").visible = false;
	}
	
});

ui("do_ALayout_Pic").on("touch",function(){
	var userId = ui("imgfullLogo").tag;//用户id
	if(userId!=null){
		openHelper.openPersonal(userId);//到他的主页
	}
})

//同意加为好友
ui("btnAccept").on("touch", function(data, e) {
	var friendApplyId = ui("lableTime").tag;
	friendHelper.acceptFriendApply(friendApplyId,function(data){
		page.fire("new_friend_reflash", friendApplyId);
		nf.toast("添加好友成功");
	});
});

//忽略好友申请
ui("btnIgnore").on("touch", function(data, e) {
	var friendApplyId = ui("lableTime").tag;
	friendHelper.ignoreFriendApply(friendApplyId,function(data){
		page.fire("new_friend_reflash", friendApplyId);
		nf.toast("已忽略");
	});
})